package net.hn.hnms.biz.plan.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import net.hn.hnms.biz.plan.service.ExecutionPeelService;
import net.hn.hnms.sys.common.core.domain.R;
import net.hn.hnms.sys.common.core.utils.DateUtils;
import net.hn.hnms.sys.common.core.web.controller.BaseController;
import net.hn.hnms.sys.common.log.annotation.Log;
import net.hn.hnms.sys.common.log.enums.BusinessType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

@Api(value = "剥离管理模块", tags = {"剥离管理"})
@RestController
@RequestMapping("/execution/peel")
public class ExecutionPeelController  extends BaseController {


    @Autowired
    private ExecutionPeelService executionPeelService;




    @ApiOperation("新增剥离 ")
//    @SaCheckPermission("plan:sale:add")
    @PostMapping("/add")
    @Log(title = "新增剥离", businessType = BusinessType.INSERT)
    public R<Void> add(String mineCode) {

        List<String> twoDaysDayDes = getTwoDaysDayDes("2023-05-01", "2023-05-31");
        for (int i = 0; i <= 30; i++) {
            String s = twoDaysDayDes.get(i);
            System.out.println(s);
            Date date = DateUtils.dateTime("yyyy-MM-dd",s);
            System.out.println(date);
//            executionPeelService.insert(i,   DateUtils.dateTime("yyyy-MM-dd",s),mineCode);
        }
        return R.ok();
    }


    private static List<String> getTwoDaysDayDes(String startDate, String endDate) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        List<String> dateList = new ArrayList<>();
        try {
            Date dateOne = sdf.parse(startDate);
            Date dateTwo = sdf.parse(endDate);
            Calendar calendar = Calendar.getInstance();
            calendar.setTime(dateOne);
            dateList.add(startDate);
            while (dateTwo.after(calendar.getTime())) {
                calendar.add(Calendar.DAY_OF_MONTH, 1);
                dateList.add(sdf.format(calendar.getTime()));
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return dateList;
    }
}
